using System;
using System.IO;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Outlook;
using TXLooker.Properties;
using MAPIFolder=Microsoft.Office.Interop.Outlook.MAPIFolder;

namespace TXLooker.Core
{
    internal class OutlookDataProvider
    {
        // Fields
        private Microsoft.Office.Interop.Outlook.Application m_application = null;
        private MAPIFolder m_AppMAPIFolderRoot = null;
        private Folder m_AppFolderRoot;
        private MAPIFolder m_deletedItemsMAPIFolder = null;
        private NameSpace m_Session;
        private string m_storeFolderPath = null;
        private string m_storePath = null;
        private int m_trialDays;
        private CommandBarPopup m_txpMenuItemCommon = null;

        // Properties
        public Application Application
        {
            get
            {
                return this.m_application;
            }
            set
            {
                if (value == null)
                {
                    throw new NullReferenceException();
                }
                this.m_application = value;
            }
        }

        public MAPIFolder AppMAPIFolderRoot
        {
            get
            {
                return this.m_AppMAPIFolderRoot;
            }
            set
            {
                if (value == null)
                {
                    throw new NullReferenceException();
                }
                this.m_AppMAPIFolderRoot = value;
            }
        }

        public CommandBarPopup AppMenuItemRoot
        {
            get
            {
                return this.m_txpMenuItemCommon;
            }
            set
            {
                if (value == null)
                {
                    throw new NullReferenceException();
                }
                this.m_txpMenuItemCommon = value;
            }
        }

        public Folder AppFolderRoot
        {
            get
            {
                return this.m_AppFolderRoot;
            }
            set
            {
                this.m_AppFolderRoot = value;
            }
        }

        public string AppStoreFolderPath
        {
            get
            {
                if (this.m_storeFolderPath == null)
                {
                    this.m_storeFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                    this.m_storeFolderPath = Path.Combine(this.m_storeFolderPath, Resources.APPLICATION_NAME);
                    if (!Directory.Exists(this.m_storeFolderPath))
                    {
                        Directory.CreateDirectory(this.m_storeFolderPath);
                    }
                }
                return this.m_storeFolderPath;
            }
        }

        public string AppStoreID
        {
            get
            {
                return ((this.AppMAPIFolderRoot == null) ? null : this.AppMAPIFolderRoot.StoreID);
            }
        }

        public MAPIFolder DeleteItemsFolder
        {
            get
            {
                return this.m_deletedItemsMAPIFolder;
            }
            set
            {
                if (value == null)
                {
                    throw new NullReferenceException();
                }
                this.m_deletedItemsMAPIFolder = value;
            }
        }

        public string OutlookStorePath
        {
            get
            {
                if (this.m_storePath == null)
                {
                    this.m_storePath = Path.Combine(this.AppStoreFolderPath, Resources.APPLICATION_NAME + ".pst");
                }
                return this.m_storePath;
            }
        }

        public NameSpace Session
        {
            get
            {
                return this.m_Session;
            }
            set
            {
                this.m_Session = value;
            }
        }

        public int TrialDays
        {
            get
            {
                return this.m_trialDays;
            }
            set
            {
                this.m_trialDays = value;
            }
        }
    }


}
